package com.company.project.service.impl;

import com.company.project.dao.ImageMapper;
import com.company.project.model.Image;
import com.company.project.model.News;
import com.company.project.service.ImageService;
import com.company.project.core.AbstractService;
import com.company.project.util.PageUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


/**
 * Created by CodeGenerator on 2018/10/08.
 */
@Service
@Transactional
public class ImageServiceImpl extends AbstractService<Image> implements ImageService {
    @Resource
    private ImageMapper imageMapper;

    //前台首页轮播图
    @Override
    public List<Image> getImgeList() {
        return imageMapper.selectImageList();
    }

    //后台查询前台首页轮播图
    @Override
    public PageUtil<Image> adminGetImageList(Integer index) {
        PageUtil<Image> pageUtil = new PageUtil();
        pageUtil.setPageSize(6);
        pageUtil.setCpage(index);
        pageUtil.setTotalRow(this.adminGetCount());
        pageUtil.setLists(imageMapper.adminSelectImageList(pageUtil));
        return pageUtil;
    }

    @Override
    public Integer adminGetCount() {
        return imageMapper.adminSelectCount();
    }

    //后台添加图片
    @Override
    public Boolean adminAddImage(Image image) {
        int i=0;
        i = imageMapper.insertSelective(image);
        if(i!=0){
            return true;
        }
        return false;
    }

    //后台修改图片
    @Override
    public Boolean adminUpdateImage(Image image) {
        int i= 0;
        i = imageMapper.adminUpdateImage(image);
        if(i!=0){
            return true;
        }
        return false;
    }

    //删除图片
    @Override
    public Boolean adminDelectImage(Image image) {
        int i = 0;
        i=imageMapper.deleteByPrimaryKey(image);
        if(i!=0){
            return true;
        }
        return false;
    }

}
